<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h3>强制更新</h3>
      <p>{{ arr }}</p>
      <!-- <p>{{ obj }}</p> -->
      <button @click="fn">btn</button>
    </div>

    <script src="../Vue.js"></script>
    <script>
      // 1. 直接改变数组长度
      // 2. 通过索引改变数组项
      // 3. 对象里面添加新属性的时候
      // 响应式失效
      new Vue({
        el: "#app",
        data: {
          arr: [1, 2, 3, 4],
          obj: {
            a: 3,
            b: 4,
          },
        },
        methods: {
          fn() {
            this.arr.length = 3;
            // this.arr = [...this.arr];
            this.arr = [].concat(this.arr);
            // console.log(this.arr);

            // this.arr[1] = 100;
            // console.log(this.arr);

            // this.obj.c = 5;
            // this.obj = { ...this.obj };
            // this.obj = Object.assign({}, this.obj);
            // console.log(this.obj);

            // 强制更新
            // this.$forceUpdate();
          },
        },
      });
    </script>
  </body>
</html>
